{% extends '../admin_base/base.html' %}

{% block title %}<title>公告</title>{% end %}
{% block body %}
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-lg-10 col-md-offset-2 main" id="main">
      <form action="" method="post" >
        <h1 class="page-header">操作</h1>
        <ol class="breadcrumb">
          <li><a href="/admin/add_blog">增加博客</a></li>
        </ol>
        <h1 class="page-header">管理 <span class="badge">{{count}}</span></h1>
        <div class="table-responsive">
          <table class="table table-striped table-hover">
            <thead>
              <tr>
                <th><span class="glyphicon glyphicon-th-large"></span> <span class="visible-lg">选择</span></th>
                <th><span class="glyphicon glyphicon-file"></span> <span class="visible-lg">标题</span></th>
                <th><span class="glyphicon glyphicon-time"></span> <span class="visible-lg">日期</span></th>
                <th><span class="glyphicon glyphicon-pencil"></span> <span class="visible-lg">操作</span></th>
              </tr>
            </thead>
            <tbody>
            {% for blog in blogs %}
              <tr>
                <td><input type="checkbox" class="input-control" name="checkbox[]" value="" /></td>
                <td class="article-title">{{blog.title}}</td>
                <td>{{blog.createtime}}</td>
                <td><a href="/admin/modify_blog?id={{blog.id}}">修改</a> <a rel="{{blog.id}}">删除</a></td>
              </tr>
            {% end %}
            </tbody>
          </table>
        </div>
      </form>
    </div>
  </div>
</section>
{% end %}
{% block end %}
<script>
//是否确认删除
$(function(){
	$("#main table tbody tr td a").click(function(){
		var name = $(this);
		var id = name.attr("rel"); //对应id
		if (event.srcElement.outerText == "删除")
		{
			if(window.confirm("此操作不可逆，是否确认？"))
			{
				$.ajax({
					type: "POST",
					url: "/admin/delete_blog",
					data: "id=" + id,
					cache: false, //不缓存此页面
					success: function (data) {
						window.location.reload();
					}
				});
			};
		};
	});
});
</script>
{% end %}
